package com.chen.pfm.slice;

import com.chen.pfm.*;

import com.chen.pfm.entity.*;

import com.chen.pfm.provider.MypageProvider;

import com.chen.pfm.utils.*;


import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.DataAbilityRemoteException;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.*;

import ohos.agp.components.element.VectorElement;
import ohos.agp.window.dialog.CommonDialog;

import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

import java.util.ArrayList;
import java.util.List;

import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_CONTENT;


public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    final static HiLogLabel
            LABEL = new HiLogLabel(HiLog.LOG_APP, 0x2022003, "MainAbilitySlice");

    TabList tabList;
    PageSlider pageSlider;

    private Text Monthbalance;//当月结余
    private Text Monthincome;//当月收入
    private Text MonthSpending;//当月支出
    private Text currentBudget;//当前预算
    private Text remainingBudget;//剩余预算
    private Text currentMonth;//本月
    private Text currentMonthSpending;//本月支出
    private Text currentMonthIncome;//本月收入
    private Text today;//今天
    private Text todaySpending;//今天支出
    private Text todayIncome;//今天收入
    private Text pastSevenDays;//过去七天
    private Text pastSevenDaysSpending;//过去七天支出
    private Text pastSevenDaysIncome;//过去七天收入
    private Text currentYear;//本年
    private Text currentYearSpending;//本年支出
    private Text currentYearIncome;//本年收入
    private Text userName;//用户昵称
    private Text userId;//用户账号
    private Text UID;//用户账号
    private Text todayNumberAccounts;//今天记账数
    StatisticsInfo statisticsInfo;
    private Text momthNumberAccounts;//月记账数
    private Text totalNumberAccounts;//总记账数
    Image profile;
    VectorElement vectorElement;
    User user;
    Integer uid;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        //有用户登录信息,让它直接跳转主界面
        String token = DataBaseUtil.GetValue(this, "token");
        if (token != null) {
            String uid =  DataBaseUtil.GetValue(this, "uid");
            if (uid == null) {
                return;
            }
            this.uid = Integer.valueOf(uid);
            HiLog.info(LABEL, "token信息不为空，直接跳转主界面！");
            user = UserDBUtil.queryOneByUid(this, this.uid);
            //计算机首页渲染数据
            statisticsInfo = new StatisticsInfo();
            statisticsInfo.statistics(this);
            statisticsInfo.setsCurrentMonthBudget(this, this.uid);
            //得到user对象

            MyToast.showMyToast(this, "登录成功，欢迎用户 " + user.getUsername());
            initMain();//初始化首页
        } else {
            HiLog.error(LABEL, "token为空，跳转登录页面");
            //跳转登录页面
            Intent loginIntent = new Intent();
            Operation operation = new Intent.OperationBuilder().withDeviceId("")
                    .withBundleName(getBundleName())
                    .withAbilityName(LoginAbility.class.getName())
                    .build();
            loginIntent.setOperation(operation);
            startAbilityForResult(loginIntent, 1000);
        }


    }

    //初始化页面数据
    private void initIndexData() {
        //当月支出
        MonthSpending = (Text) findComponentById(ResourceTable.Id_current_month_expenses);
        //当月收入
        Monthincome = (Text) findComponentById(ResourceTable.Id_current_month_incomes);
        //当月结余
        Monthbalance = (Text) findComponentById(ResourceTable.Id_current_month_surplus);
        //当前预算
        currentBudget = (Text) findComponentById(ResourceTable.Id_current_month_budget);
        //剩余预算
        remainingBudget = (Text) findComponentById(ResourceTable.Id_current_month_balance);
        //今天渲染数据
        today = (Text) findComponentById(ResourceTable.Id_today);

        todaySpending = (Text) findComponentById(ResourceTable.Id_todaySpending);

        todayIncome = (Text) findComponentById(ResourceTable.Id_todayIncome);

        //过去七天渲染数据
        pastSevenDays = (Text) findComponentById(ResourceTable.Id_pastSevenDays_bottom_text1);

        pastSevenDaysSpending = (Text) findComponentById(ResourceTable.Id_pastSevenDaysSpending);

        pastSevenDaysIncome = (Text) findComponentById(ResourceTable.Id_pastSevenDaysIncome);
        //本月渲染数据
        currentMonth = (Text) findComponentById(ResourceTable.Id_month_bottom_text1);

        currentMonthSpending = (Text) findComponentById(ResourceTable.Id_currentMonthSpending);

        currentMonthIncome = (Text) findComponentById(ResourceTable.Id_currentMonthIncome);
        //本年渲染数据
        currentYear = (Text) findComponentById(ResourceTable.Id_year_bottom_text1);

        currentYearSpending = (Text) findComponentById(ResourceTable.Id_currentYearSpending);

        currentYearIncome = (Text) findComponentById(ResourceTable.Id_currentYearIncome);

//        getUITaskDispatcher().asyncDispatch(() -> {

        //如果不存在，那么就插入一个当月的报表
        MonthSpending.setText(MyUtil.getStrBalance(statisticsInfo.getsMonthSpending()));
        Monthincome.setText(MyUtil.getStrBalance(statisticsInfo.getsMonthIncome()));
        Monthbalance.setText(MyUtil.getStrBalance(statisticsInfo.getMonthbalance()));

        //今天数据渲染
        todaySpending.setText(String.valueOf(statisticsInfo.getStodaySpending()));
        todayIncome.setText(String.valueOf(statisticsInfo.getStodayIncome()));
        //过去七天渲染数据
        pastSevenDaysSpending.setText(MyUtil.getStrBalance(statisticsInfo.getSpastSevenDaysSpending()));
        pastSevenDaysIncome.setText(MyUtil.getStrBalance(statisticsInfo.getSpastSevenDaysIncome()));
        //本月渲染数据
        currentMonthSpending.setText(MyUtil.getStrBalance(statisticsInfo.getsMonthSpending()));
        currentMonthIncome.setText(MyUtil.getStrBalance(statisticsInfo.getsMonthIncome()));
        //本年渲染
        currentYearSpending.setText(MyUtil.getStrBalance(statisticsInfo.getsYearSpending()));
        currentYearIncome.setText(MyUtil.getStrBalance(statisticsInfo.getsYearIncome()));


        statisticsInfo.setsCurrentMonthBudget(this, uid);
        //预算
        currentBudget.setText(MyUtil.getStrBalance(statisticsInfo.getsCurrentMonthBudget()));
        //本月可用
        remainingBudget.setText(MyUtil.getStrBalance(statisticsInfo.getRemainingBudget()));

        //下半部分的界面渲染
        //今天渲染数据
        today.setText(DateUtils.getCurrentMonth() + "月" + DateUtils.getCurrentDay() + "日");
        //过去七天渲染数据
        pastSevenDays.setText(DateUtils.getPastSevenDaysStartToEnd());
        //本月渲染数据
        currentMonth.setText(DateUtils.getCurrentMonthStartToEnd());
        //本年渲染
        currentYear.setText(DateUtils.getCurrentYear() + "年");
//        });
    }

    //初始化主页
    void initMain() {
        tabList = (TabList) findComponentById(ResourceTable.Id_main_tablist);
        pageSlider = (PageSlider) findComponentById(ResourceTable.Id_main_PageSlider);
        //加载主页的导航栏
        String[] tabTexts = {"首页", "我的"};
        for (int i = 0; i < tabTexts.length; i++) {
            TabList.Tab tab = tabList.new Tab(this);
            tab.setText(tabTexts[i]);
            tabList.addTab(tab);
        }

        //绑定导航栏的页面切换，反之也页面切换引起导航栏选择切换
        List<Integer> list = new ArrayList<>();
        list.add(ResourceTable.Layout_ability_index);
        list.add(ResourceTable.Layout_ability_usercenter);


        MypageProvider mypageProvider = new MypageProvider(list, this);
        pageSlider.setProvider(mypageProvider);//设置Provider


        //导航栏和页面的联动
        tabList.addTabSelectedListener(new TabList.TabSelectedListener() {
            @Override
            public void onSelected(TabList.Tab tab) {
                int position = tab.getPosition();
                pageSlider.setCurrentPage(position);
                if (position == 0) {//首页
                    initIndexPage();
                    initIndexData();//初始化页面数据
                } else {//我的

                    initUserCenterData();//初始化页面数据
                    initUserCenter();

                }
            }

            @Override
            public void onUnselected(TabList.Tab tab) {

            }

            @Override
            public void onReselected(TabList.Tab tab) {

            }
        });
        pageSlider.addPageChangedListener(new PageSlider.PageChangedListener() {
            @Override
            public void onPageSliding(int i, float v, int i1) {

            }

            @Override
            public void onPageSlideStateChanged(int i) {

            }

            @Override
            public void onPageChosen(int i) {
                if (tabList.getSelectedTabIndex() != i) {
                    tabList.selectTabAt(i);
                }
            }
        });
        tabList.selectTabAt(0);
        HiLog.info(LABEL, "导航栏加载完成！");
    }

    //用户首页
    private void initIndexPage() {
        HiLog.info(LABEL, "你来到了用户首页");
        //跳转到增加记账页面
        findComponentById(ResourceTable.Id_keep_one_btn).setClickedListener(component -> {
            Intent intent = new Intent();
            HiLog.info(LABEL, "点击了增加记账页面");
            Operation operation = new Intent.OperationBuilder().withDeviceId("")
                    .withBundleName(getBundleName())
                    .withAbilityName(KeepAccountsAbility.class.getName())
                    .build();
            intent.setOperation(operation);
//            startAbility(intent);
            startAbilityForResult(intent, 1001);

        });
        //今天
        findComponentById(ResourceTable.Id_today_layout).setClickedListener(this);
        //近七天
        findComponentById(ResourceTable.Id_week_layout).setClickedListener(this);
        //本月
        findComponentById(ResourceTable.Id_month_layout).setClickedListener(this);
        //本年
        findComponentById(ResourceTable.Id_year_layout).setClickedListener(this);
    }


    @Override
    protected void onAbilityResult(int requestCode, int resultCode, Intent resultData) {
        super.onAbilityResult(requestCode, resultCode, resultData);
        switch (requestCode) {
            case 1000://登录模块完成
                onStart(resultData);
                break;
            case 1001://记账
                statisticsInfo.statistics(this);
                initIndexData();
                break;
            case 1002://记账数
                //首页的账单信息显示刷新
                statisticsInfo.statistics(this);
                initIndexData();
                break;
            case 1003://个人昵称
                user = UserDBUtil.queryOneByUid(this, uid);
                userName.setText(user.getUsername());
                //头像
                setProfile();
                break;
            case 2003://修改密码
                String token = DataBaseUtil.GetValue(this, "token");
                if (token == null) {
                    Intent loginIntent = new Intent();
                    Operation operation = new Intent.OperationBuilder().withDeviceId("")
                            .withBundleName(getBundleName())
                            .withAbilityName(LoginAbility.class.getName())
                            .build();
                    loginIntent.setOperation(operation);
                    startAbilityForResult(loginIntent, 2000);
                }
                break;
            case 2000://重新登录加载数据
                String uid =  DataBaseUtil.GetValue(this, "uid");
                if (uid == null) {
                    MyToast.showMyToast(this,"数据加载失败，已退出");
                    terminate();
                }
                this.uid = Integer.valueOf(uid);
                user = UserDBUtil.queryOneByUid(this, this.uid);
                //计算首页渲染数据
                statisticsInfo = new StatisticsInfo();
                statisticsInfo.statistics(this);
                statisticsInfo.setsCurrentMonthBudget(this, this.uid);
                //得到user对象
                MyToast.showMyToast(this, "登录成功，欢迎用户 " + user.getUsername());
                tabList.selectTabAt(0);
                break;
        }

    }

    //点击按键匹配操作
    @Override
    public void onClick(Component component) {
        int componentId = component.getId();
        switch (componentId) {
            case ResourceTable.Id_today_layout: {//今天
                //首页跳转的日期统计页面
                HiLog.info(LABEL, "点击了今天按钮！");
                Intent intent = new Intent();
                intent.setParam("operation", "今天");
                intent.setParam("StatisticsDateTime", DateUtils.getStrCurrentYearandMonthandDay());
                Operation operation = new Intent.OperationBuilder().withDeviceId("")//主路由
                        .withBundleName(getBundleName())
                        .withAbilityName(DateStatisticsAbility.class.getName())
                        .build();
                intent.setOperation(operation);
                startAbilityForResult(intent, 1002);
            }
            break;
            case ResourceTable.Id_week_layout: {//近七天

                //首页跳转DateStatisticsAbility的日期统计页面
                HiLog.info(LABEL, "点击了建议近七天按钮！");
                Intent intent = new Intent();
                intent.setParam("operation", "近七天");
                String currentYearandMonthandDay = DateUtils.getStrCurrentYearandMonthandDay();
                intent.setParam("StatisticsDateTime_start", currentYearandMonthandDay);
                intent.setParam("StatisticsDateTime", DateUtils.getCurrentTimePastDate(7));
                Operation operation = new Intent.OperationBuilder().withDeviceId("")//主路由
                        .withBundleName(getBundleName())
                        .withAbilityName(DateStatisticsAbility.class.getName())
                        .build();
                intent.setOperation(operation);
                startAbilityForResult(intent, 1002);
            }
            break;
            case ResourceTable.Id_month_layout: {//月份
                //首页跳转DateStatisticsAbility的日期统计页面
                HiLog.info(LABEL, "点击了建议近本月按钮！");
                Intent intent = new Intent();
                intent.setParam("operation", "本月");
                intent.setParam("StatisticsDateTime", DateUtils.getStrCurrentYearandMonth());
                Operation operation = new Intent.OperationBuilder().withDeviceId("")//主路由
                        .withBundleName(getBundleName())
                        .withAbilityName(DateStatisticsAbility.class.getName())
                        .build();
                intent.setOperation(operation);
                startAbilityForResult(intent, 1002);
            }
            break;
            case ResourceTable.Id_year_layout: {//本年
                //首页跳转DateStatisticsAbility的日期统计页面
                HiLog.info(LABEL, "点击了建议近本年按钮！");
                Intent intent = new Intent();
                intent.setParam("operation", "本年");
                intent.setParam("StatisticsDateTime", DateUtils.getStrCurrentYear());
                Operation operation = new Intent.OperationBuilder().withDeviceId("")//主路由
                        .withBundleName(getBundleName())
                        .withAbilityName(DateStatisticsAbility.class.getName())
                        .build();
                intent.setOperation(operation);
                startAbilityForResult(intent, 1002);
            }
            break;
        }
    }

    //用户中心******************************************************
    private void initUserCenterData() {//初始化用户数据
        //头像
        profile = (Image) findComponentById(ResourceTable.Id_icon_usercenter_profile);
        //用户
        user = UserDBUtil.queryOneByUid(this, this.uid);

        userName = (Text) findComponentById(ResourceTable.Id_userName);
        //账号
        userId = (Text) findComponentById(ResourceTable.Id_userId);
        //UID
        UID = (Text) findComponentById(ResourceTable.Id_UID);
        //今天记账数
        todayNumberAccounts = (Text) findComponentById(ResourceTable.Id_todayNumberAccounts);
        //月记账数
        momthNumberAccounts = (Text) findComponentById(ResourceTable.Id_momthNumberAccounts);
        //总记账数
        totalNumberAccounts = (Text) findComponentById(ResourceTable.Id_totalNumberAccounts);

        todayNumberAccounts.setText(String.valueOf(AccountDBUtil.statisticalTodayNumberAccounts(this)));

        momthNumberAccounts.setText(String.valueOf(AccountDBUtil.statisticalMomthNumberAccounts(this)));

        totalNumberAccounts.setText(String.valueOf(AccountDBUtil.statisticalTotalNumberAccounts(this)));
        //用户页面的数据加载、刷新
        //昵称
        userName.setText(user.getUsername());
        userId.setText(user.getUserid());
        UID.setText(String.valueOf(user.getUid()));
        setProfile();
    }

    //根据性别设置头像
    void setProfile() {
        if ("男".equals(user.getGender())) {
            vectorElement = new VectorElement(this, ResourceTable.Graphic_icon_usercenter_profile_boy);
            profile.setPixelMap(null);
        } else if ("女".equals(user.getGender())) {
            vectorElement = new VectorElement(this, ResourceTable.Graphic_icon_usercenter_profile_girl);
            profile.setPixelMap(null);
        } else {
            vectorElement = new VectorElement(this, ResourceTable.Graphic_icon_usercenter_girl);
        }
        profile.setBackground(vectorElement);
    }

    //监听用户中心按钮
    private void initUserCenter() {

        HiLog.info(LABEL, "你来到了用户中心");
         /*
        <!----第一个卡片-->
         */
        //用户信息
        findComponentById(ResourceTable.Id_layout_usercenter_userinfo).setClickedListener((component -> {
            Intent intent = new Intent();
            HiLog.info(LABEL, "点击了用户信息按钮");
            Operation operation = new Intent.OperationBuilder().withDeviceId("")
                    .withBundleName(getBundleName())
                    .withAbilityName(UserInfoAbility.class.getName())
                    .build();
            intent.setOperation(operation);
            startAbilityForResult(intent, 1003);
        }));

        //修改密码
        findComponentById(ResourceTable.Id_layout_usercenter_alterpwd).setClickedListener(component -> {
            //用户修改密码管理
            HiLog.info(LABEL, "点击了修改密码按钮！");
            Intent intent = new Intent();
            Operation operation = new Intent.OperationBuilder().withDeviceId("")
                    .withAction("ChangePasswordSlice")
                    .withBundleName(getBundleName())
                    .withAbilityName(UserInfoAbility.class.getName())
                    .build();
            intent.setOperation(operation);
            startAbilityForResult(intent, 2003);
        });
        //预算管理
        findComponentById(ResourceTable.Id_layout_usercenter_budget_management).setClickedListener((component -> {
            Intent intent = new Intent();
            intent.setParam("Monthincome", statisticsInfo.getsMonthIncome());
            intent.setParam("MonthSpending", statisticsInfo.getsMonthSpending());
            HiLog.info(LABEL, "点击了预算管理页面");
            Operation operation = new Intent.OperationBuilder().withDeviceId("")
                    .withBundleName(getBundleName())
                    .withAbilityName(BudgetManagementAbility.class.getName())
                    .build();
            intent.setOperation(operation);
            startAbility(intent);
        }));
        //分类管理按钮
        findComponentById(ResourceTable.Id_layout_usercenter_classify_management).setClickedListener((component) -> {
            //用户中心跳转分类管理
            HiLog.info(LABEL, "点击了分类管理按钮！");
            Intent intent = new Intent();
            Operation operation = new Intent.OperationBuilder().withDeviceId("")
                    .withBundleName(getBundleName())
                    .withAbilityName(ClassifiedManagementAbility.class.getName())
                    .build();
            intent.setOperation(operation);
            startAbility(intent);
        });
          /*
        <!----第二个卡片-->
         */
        //账单查询
        findComponentById(ResourceTable.Id_layout_usercenter_search).setClickedListener(component -> {
            Intent intent = new Intent();
            Operation operation = new Intent.OperationBuilder().withDeviceId("")//主路由
                    .withBundleName(getBundleName())
                    .withAbilityName(SearchAbility.class.getName())
                    .build();
            intent.setOperation(operation);
            startAbility(intent);
        });
        //图表统计
        findComponentById(ResourceTable.Id_layout_usercenter_statistics).setClickedListener(component -> {
            //用户中心跳转关于我们
            getUITaskDispatcher().asyncDispatch(() -> {
                MyToast.showMyToast(this, "正在加载数据...");


                HiLog.info(LABEL, "点击了图表统计按钮！");

                Intent intent = new Intent();
                Operation operation = new Intent.OperationBuilder().withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName(GraphicStatisticsAbility.class.getName())
                        .build();
                intent.setOperation(operation);

                startAbility(intent);
            });
        });
        //资产管理
        findComponentById(ResourceTable.Id_layout_usercenter_asset).setClickedListener(component -> {
            //用户中心跳转关于我们
            HiLog.info(LABEL, "点击了资产管理按钮！");
            Intent intent = new Intent();
            Operation operation = new Intent.OperationBuilder().withDeviceId("")
                    .withAction("AssetManagementSlice")
                    .withBundleName(getBundleName())
                    .withAbilityName(DateStatisticsAbility.class.getName())
                    .build();
            intent.setOperation(operation);
            startAbility(intent);

        });
        //收支管理
        findComponentById(ResourceTable.Id_layout_usercenter_bill).setClickedListener(component -> {
            //用户中心跳转关于我们
            HiLog.info(LABEL, "点击了收支管理按钮！");
            Intent intent = new Intent();
            Operation operation = new Intent.OperationBuilder().withDeviceId("")
                    .withAction("BillManagementSlice")
                    .withBundleName(getBundleName())
                    .withAbilityName(DateStatisticsAbility.class.getName())
                    .build();
            intent.setOperation(operation);
            startAbility(intent);

        });

             /*
        <!----第三个卡片-->
         */
        //版本信息
        findComponentById(ResourceTable.Id_layout_version_info).setClickedListener(component -> {
            //用户中心跳转版本信息
            HiLog.info(LABEL, "点击了版本信息按钮！");
            Intent intent = new Intent();
            Operation operation = new Intent.OperationBuilder().withDeviceId("")//主路由
                    .withBundleName(getBundleName())
                    .withAbilityName(AppInfoAbility.class.getName())
                    .build();
            intent.setOperation(operation);
            startAbility(intent);

        });
        //应用评分
        findComponentById(ResourceTable.Id_layout_usercenter_grade).setClickedListener(component -> {
            //用户中心跳转应用评分
            HiLog.info(LABEL, "点击了应用评分按钮！");
            Intent intent = new Intent();
            Operation operation = new Intent.OperationBuilder().withDeviceId("")
                    .withAction("AppGradeSlice")
                    .withBundleName(getBundleName())
                    .withAbilityName(AppInfoAbility.class.getName())
                    .build();
            intent.setOperation(operation);
            startAbility(intent);

        });
        //关于我们
        findComponentById(ResourceTable.Id_layout_usercenter_aboutus).setClickedListener(component -> {
            //用户中心跳转关于我们
            HiLog.info(LABEL, "点击了关于我们按钮！");
            Intent intent = new Intent();
            Operation operation = new Intent.OperationBuilder().withDeviceId("")
                    .withAction("AboutUsSlice")
                    .withBundleName(getBundleName())
                    .withAbilityName(AppInfoAbility.class.getName())
                    .build();
            intent.setOperation(operation);
            startAbility(intent);

        });
        /*
        <!----第四个卡片-->
         */
        //登录退出按钮
        findComponentById(ResourceTable.Id_logout).setClickedListener(this::logout);


    }

    //退出登录
    private void logout(Component component) {
        HiLog.info(LABEL, "点击了退出按钮！");
        //布局加载
        Component parse = LayoutScatter.getInstance(this).parse(ResourceTable.Layout_dialog_logout_confirm, null, false);
        //创建显示气窗
        CommonDialog dialog = new CommonDialog(this);
        dialog.setOffset(0, 10);
        dialog.setContentCustomComponent(parse);
        dialog.setSize(MATCH_CONTENT, MATCH_CONTENT);
        //取消按钮
        Button logout_cancel = (Button) parse.findComponentById(ResourceTable.Id_logout_cancel);
        //确定按钮
        Button logout_ok = (Button) parse.findComponentById(ResourceTable.Id_logout_ok);

        dialog.show();
        logout_cancel.setClickedListener(c -> {
            dialog.destroy();
            MyToast.showMyToast(this, "已取消");

        });
        logout_ok.setClickedListener(c -> {
            dialog.hide();
            DataBaseUtil.deleteValue(this, "token");
            int deluid = DataBaseUtil.deleteValue(this, "uid");
            //退出时，删除该账户的全部删除数据
            try {
                AccountDBUtil.deleteByUid(this, deluid);
                ClassifyDBUtil.deleteByUid(this, deluid);
                StatementsDBUtil.deleteByUid(this, deluid);
                UserDBUtil.deleteByUid(this, deluid);
            } catch (DataAbilityRemoteException e) {
                e.printStackTrace();
            }


            MyToast.showMyToast(this, "已退出");
            Intent intent = new Intent();
            Operation operation = new Intent.OperationBuilder().withDeviceId("")
                    .withBundleName(getBundleName())
                    .withAbilityName(LoginAbility.class.getName())
                    .build();
            intent.setOperation(operation);
            startAbilityForResult(intent, 2000);

        });
    }


}